import java.applet.Applet; 
import java.awt.*; 
import java.awt.event.*; 
public class main extends Applet implements Runnable {
	boolean game = true;
	MouseInput mouse = new MouseInput();
	Thread th = new Thread(this);
	Image dbImage;import java.applet.Applet; 
import java.awt.*; 
import java.awt.event.*; 
public class main extends Applet implements Runnable {
	boolean game = true;
	MouseInput mouse = new MouseInput();
	Thread th = new Thread(this);
	Image dbImage;
	Graphics dbGraphics;
	Towers towers[] = new Towers[50];
	String dispBox[] = {"Simple", "Heat Seek" , "Advanced" , "Adv. Heat Seek" , " Super", "Destory", "Nothing"};
	int prices[] = {50, 100, 200, 400, 1600, 0, 0};
	//Path = {X, Y, WIDTH, HEIGHT
	int path[][] = {{50, 0, 50, 100},
			{50, 100, 150, 50},
			{200, 100, 50, 150},
			{100, 250, 150, 50},
			{100, 300, 50, 150},
			{100, 450, 250, 50},
			{350, 450, 50, 200},
			{350, 650, 200, 50},
			{550, 650, 50, 100}};
	int end[] = {550, 750, 50, 50};
	int towerSelected = 0;
	public void start() {
		this.addMouseListener(mouse);
	}
	public void checkMouseClick() {
		if (mouse.X > 700)
			checkGUI();
		System.out.print(mouse.X + " and " + mouse.Y + "\n");
	}
	public void checkGUI() {
		for (int i = 0; i < dispBox.length; i++) {
			if ((mouse.X >= 700) && (mouse.X <= 790) && (mouse.Y >= 50 + i*75) && (mouse.Y <= 100 + i*75))
				towerSelected = i;
		}
	}
	public void run() {  
		while(game) {
			repaint();
			if (mouse.clicked) {
				checkMouseClick();
				mouse.clicked = false;
			}
			try { 
				th.sleep(10); 
			} 
			catch(Exception e){
				
			} 
		} 
	} 
	public void update(Graphics g) {
		if (dbImage == null) {
			dbImage = createImage (this.getSize().width, this.getSize().height);
			dbGraphics = dbImage.getGraphics();
		}
		dbGraphics.setColor(Color.gray);
		dbGraphics.fillRect(0, 0, this.getSize().width, this.getSize().height);
		dbGraphics.setColor(getForeground());
		paint(dbGraphics);
		g.drawImage(dbImage, 0, 0, this);
	}  
	public void paint(Graphics g) {
		//Colored Boxes
		g.setColor(Color.lightGray);
		g.fillRect(690, 0, 110, 800);
		//End Colored Boxes
		//Start Path and end
		for (int i = 0; i < path.length; i++)
			g.fillRect(path[i][0], path[i][1], path[i][2], path[i][3]);
		g.setColor(Color.RED);
		g.fillRect(end[0], end[1], end[2], end[3]);
		//End path and end
		g.setColor(Color.BLACK);
		//Tower Selection
		for (int i = 0; i < dispBox.length; i++) {
			g.drawRect(700, 50 + i*75, 90, 50);
			g.drawString(dispBox[i], 705, 70 + i *75);
			g.drawString("$" + Integer.toString(prices[i]), 710, 85 + i*75);
		}
	}
	public void init() { 
		th.start();
		setSize(800, 800);
		repaint();
	} 
	public void stop() { 
		game = false;
	} 
} 

	Graphics dbGraphics;
	Towers towers[] = new Towers[50];
	String dispBox[] = {"Simple", "Heat Seek" , "Advanced" , "Adv. Heat Seek" , " Super", "Destory", "Nothing"};
	int prices[] = {50, 100, 200, 400, 1600, 0, 0};
	int towerSelected = 0;
	public void start() {
		this.addMouseListener(mouse);
	}
	public void checkMouseClick() {
		if (mouse.X > 700)
			checkGUI();
		System.out.print(mouse.X + " and " + mouse.Y + "\n");
	}
	public void checkGUI() {
		for (int i = 0; i < dispBox.length; i++) {
			if ((mouse.X >= 700) && (mouse.X <= 799) && (mouse.Y >= 50 + i*75) && (mouse.Y <= 100 + i*75))
				towerSelected = i;
		}
	}
	public void run() {  
		while(game) {
			repaint();
			if (mouse.clicked) {
				checkMouseClick();
				mouse.clicked = false;
			}
			try { 
				th.sleep(10); 
			} 
			catch(Exception e){
				
			} 
		} 
	} 
	public void update(Graphics g) {
		if (dbImage == null) {
			dbImage = createImage (this.getSize().width, this.getSize().height);
			dbGraphics = dbImage.getGraphics();
		}
		dbGraphics.setColor(getBackground());
		dbGraphics.fillRect(0, 0, this.getSize().width, this.getSize().height);
		dbGraphics.setColor(getForeground());
		paint(dbGraphics);
		g.drawImage(dbImage, 0, 0, this);
	}  
	public void paint(Graphics g) {
		for (int i = 0; i < dispBox.length; i++) {
			g.drawRect(700, 50 + i*75, 99, 50);
			g.drawString(dispBox[i], 710, 70 + i *75);
			g.drawString("$" + Integer.toString(prices[i]), 710, 85 + i*75);
		}
	}
	public void init() { 
		th.start();
		setSize(800, 800);
		repaint();
	} 
	public void stop() { 
		game = false;
	} 
} 
